require "test/unit"
  
  C = "top level"
  class AboutConstants < Test::Unit::TestCase
    C = "nested"

    def test_nested_constants_may_also_be_referenced_with_relative_paths
      assert_equal "nested", C
    end
    #单独使用常量时作为绝对路径取值

    def test_top_level_constants_are_referenced
       assert_equal "top level", ::C
    end
    #使用顶级常量，即常量原意加上::

    def test_nested_constants_are_referenced_by_their_complete_path
      assert_equal "nested", AboutConstants::C
      assert_equal "nested", ::AboutConstants:: C
    end
     # 引用常量是引用的完整路径里面的常量值


    class Animal
      LEGS = 4
      def legs_in_animal
        LEGS
      end

      class NestedAnimal
        def legs_in_nested_animal
          LEGS
        end
      end
    end

    def test_nested_classes_inherit_constans_from_enclosing_classes
      assert_equal 4, Animal::NestedAnimal.new.legs_in_nested_animal
    end
  # NestedAnimal.new.legs_in_nested_animal = LEGS， 通过Animal::string 访问Animal里面的内容，故为4

    class Reptile < Animal
      def legs_in_reptile
        LEGS
      end
    end

    def test_subclasses_inherit_constants_from_parent_classes
      assert_equal 4, Reptile.new.legs_in_reptile
    end
  # Retile.new.legs_in_reptile = LEGS， Reptile继承Animal方法，故为4
  
    class MyAnimals
      LEGS = 2
    
      class Bird < Animal
        def legs_in_bird
          LEGS
        end
      end 
    end
  
    def test_strings
      assert_equal 2, MyAnimals::Bird.new.legs_in_bird
    end
  #Bird.new.legs_in_bird = LEGS, 然后访问MyAnimal里面的LEGS，故为2

    class MyAnimals::Oyster < Animal
      def legs_in_oyster
        LEGS
      end
    end

    def test_strings
      assert_equal 4, MyAnimals::Oyster.new.legs_in_oyster
    end
  #本身后面的就等于LEGS， 继承Animal的方法，故为4
  end

